home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / UserString.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  15KB  |  388 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''A user-defined wrapper around string objects
  5.  
  6. Note: string objects have grown methods in Python 1.6
  7. This module requires Python 1.6 or later.
  8. '''
  9. import sys
  10. import collections
  11. __all__ = [
  12.     'UserString',
  13.     'MutableString']
  14.  
  15. class UserString(collections.Sequence):
  16.     
  17.     def __init__(self, seq):
  18.         if isinstance(seq, basestring):
  19.             self.data = seq
  20.         elif isinstance(seq, UserString):
  21.             self.data = seq.data[:]
  22.         else:
  23.             self.data = str(seq)
  24.  
  25.     
  26.     def __str__(self):
  27.         return str(self.data)
  28.  
  29.     
  30.     def __repr__(self):
  31.         return repr(self.data)
  32.  
  33.     
  34.     def __int__(self):
  35.         return int(self.data)
  36.  
  37.     
  38.     def __long__(self):
  39.         return long(self.data)
  40.  
  41.     
  42.     def __float__(self):
  43.         return float(self.data)
  44.  
  45.     
  46.     def __complex__(self):
  47.         return complex(self.data)
  48.  
  49.     
  50.     def __hash__(self):
  51.         return hash(self.data)
  52.  
  53.     
  54.     def __cmp__(self, string):
  55.         if isinstance(string, UserString):
  56.             return cmp(self.data, string.data)
  57.         return cmp(self.data, string)
  58.  
  59.     
  60.     def __contains__(self, char):
  61.         return char in self.data
  62.  
  63.     
  64.     def __len__(self):
  65.         return len(self.data)
  66.  
  67.     
  68.     def __getitem__(self, index):
  69.         return self.__class__(self.data[index])
  70.  
  71.     
  72.     def __getslice__(self, start, end):
  73.         start = max(start, 0)
  74.         end = max(end, 0)
  75.         return self.__class__(self.data[start:end])
  76.  
  77.     
  78.     def __add__(self, other):
  79.         if isinstance(other, UserString):
  80.             return self.__class__(self.data + other.data)
  81.         if isinstance(other, basestring):
  82.             return self.__class__(self.data + other)
  83.         return self.__class__(self.data + str(other))
  84.  
  85.     
  86.     def __radd__(self, other):
  87.         if isinstance(other, basestring):
  88.             return self.__class__(other + self.data)
  89.         return self.__class__(str(other) + self.data)
  90.  
  91.     
  92.     def __mul__(self, n):
  93.         return self.__class__(self.data * n)
  94.  
  95.     __rmul__ = __mul__
  96.     
  97.     def __mod__(self, args):
  98.         return self.__class__(self.data % args)
  99.  
  100.     
  101.     def capitalize(self):
  102.         return self.__class__(self.data.capitalize())
  103.  
  104.     
  105.     def center(self, width, *args):
  106.         return self.__class__(self.data.center(width, *args))
  107.  
  108.     
  109.     def count(self, sub, start = 0, end = sys.maxint):
  110.         return self.data.count(sub, start, end)
  111.  
  112.     
  113.     def decode(self, encoding = None, errors = None):
  114.         if encoding:
  115.             if errors:
  116.                 return self.__class__(self.data.decode(encoding, errors))
  117.             return self.__class__(self.data.decode(encoding))
  118.         encoding
  119.         return self.__class__(self.data.decode())
  120.  
  121.     
  122.     def encode(self, encoding = None, errors = None):
  123.         if encoding:
  124.             if errors:
  125.                 return self.__class__(self.data.encode(encoding, errors))
  126.             return self.__class__(self.data.encode(encoding))
  127.         encoding
  128.         return self.__class__(self.data.encode())
  129.  
  130.     
  131.     def endswith(self, suffix, start = 0, end = sys.maxint):
  132.         return self.data.endswith(suffix, start, end)
  133.  
  134.     
  135.     def expandtabs(self, tabsize = 8):
  136.         return self.__class__(self.data.expandtabs(tabsize))
  137.  
  138.     
  139.     def find(self, sub, start = 0, end = sys.maxint):
  140.         return self.data.find(sub, start, end)
  141.  
  142.     
  143.     def index(self, sub, start = 0, end = sys.maxint):
  144.         return self.data.index(sub, start, end)
  145.  
  146.     
  147.     def isalpha(self):
  148.         return self.data.isalpha()
  149.  
  150.     
  151.     def isalnum(self):
  152.         return self.data.isalnum()
  153.  
  154.     
  155.     def isdecimal(self):
  156.         return self.data.isdecimal()
  157.  
  158.     
  159.     def isdigit(self):
  160.         return self.data.isdigit()
  161.  
  162.     
  163.     def islower(self):
  164.         return self.data.islower()
  165.  
  166.     
  167.     def isnumeric(self):
  168.         return self.data.isnumeric()
  169.  
  170.     
  171.     def isspace(self):
  172.         return self.data.isspace()
  173.  
  174.     
  175.     def istitle(self):
  176.         return self.data.istitle()
  177.  
  178.     
  179.     def isupper(self):
  180.         return self.data.isupper()
  181.  
  182.     
  183.     def join(self, seq):
  184.         return self.data.join(seq)
  185.  
  186.     
  187.     def ljust(self, width, *args):
  188.         return self.__class__(self.data.ljust(width, *args))
  189.  
  190.     
  191.     def lower(self):
  192.         return self.__class__(self.data.lower())
  193.  
  194.     
  195.     def lstrip(self, chars = None):
  196.         return self.__class__(self.data.lstrip(chars))
  197.  
  198.     
  199.     def partition(self, sep):
  200.         return self.data.partition(sep)
  201.  
  202.     
  203.     def replace(self, old, new, maxsplit = -1):
  204.         return self.__class__(self.data.replace(old, new, maxsplit))
  205.  
  206.     
  207.     def rfind(self, sub, start = 0, end = sys.maxint):
  208.         return self.data.rfind(sub, start, end)
  209.  
  210.     
  211.     def rindex(self, sub, start = 0, end = sys.maxint):
  212.         return self.data.rindex(sub, start, end)
  213.  
  214.     
  215.     def rjust(self, width, *args):
  216.         return self.__class__(self.data.rjust(width, *args))
  217.  
  218.     
  219.     def rpartition(self, sep):
  220.         return self.data.rpartition(sep)
  221.  
  222.     
  223.     def rstrip(self, chars = None):
  224.         return self.__class__(self.data.rstrip(chars))
  225.  
  226.     
  227.     def split(self, sep = None, maxsplit = -1):
  228.         return self.data.split(sep, maxsplit)
  229.  
  230.     
  231.     def rsplit(self, sep = None, maxsplit = -1):
  232.         return self.data.rsplit(sep, maxsplit)
  233.  
  234.     
  235.     def splitlines(self, keepends = 0):
  236.         return self.data.splitlines(keepends)
  237.  
  238.     
  239.     def startswith(self, prefix, start = 0, end = sys.maxint):
  240.         return self.data.startswith(prefix, start, end)
  241.  
  242.     
  243.     def strip(self, chars = None):
  244.         return self.__class__(self.data.strip(chars))
  245.  
  246.     
  247.     def swapcase(self):
  248.         return self.__class__(self.data.swapcase())
  249.  
  250.     
  251.     def title(self):
  252.         return self.__class__(self.data.title())
  253.  
  254.     
  255.     def translate(self, *args):
  256.         return self.__class__(self.data.translate(*args))
  257.  
  258.     
  259.     def upper(self):
  260.         return self.__class__(self.data.upper())
  261.  
  262.     
  263.     def zfill(self, width):
  264.         return self.__class__(self.data.zfill(width))
  265.  
  266.  
  267.  
  268. class MutableString(UserString, collections.MutableSequence):
  269.     """mutable string objects
  270.  
  271.     Python strings are immutable objects.  This has the advantage, that
  272.     strings may be used as dictionary keys.  If this property isn't needed
  273.     and you insist on changing string values in place instead, you may cheat
  274.     and use MutableString.
  275.  
  276.     But the purpose of this class is an educational one: to prevent
  277.     people from inventing their own mutable string class derived
  278.     from UserString and than forget thereby to remove (override) the
  279.     __hash__ method inherited from UserString.  This would lead to
  280.     errors that would be very hard to track down.
  281.  
  282.     A faster and better solution is to rewrite your program using lists."""
  283.     
  284.     def __init__(self, string = ''):
  285.         warnpy3k = warnpy3k
  286.         import warnings
  287.         warnpy3k('the class UserString.MutableString has been removed in Python 3.0', stacklevel = 2)
  288.         self.data = string
  289.  
  290.     __hash__ = None
  291.     
  292.     def __setitem__(self, index, sub):
  293.         if isinstance(index, slice):
  294.             if isinstance(sub, UserString):
  295.                 sub = sub.data
  296.             elif not isinstance(sub, basestring):
  297.                 sub = str(sub)
  298.             
  299.             (start, stop, step) = index.indices(len(self.data))
  300.             if step == -1:
  301.                 start = stop + 1
  302.                 stop = start + 1
  303.                 sub = sub[::-1]
  304.             elif step != 1:
  305.                 raise TypeError, 'invalid step in slicing assignment'
  306.             
  307.             start = min(start, stop)
  308.             self.data = self.data[:start] + sub + self.data[stop:]
  309.         elif index < 0:
  310.             index += len(self.data)
  311.         
  312.         if index < 0 or index >= len(self.data):
  313.             raise IndexError
  314.         index >= len(self.data)
  315.         self.data = self.data[:index] + sub + self.data[index + 1:]
  316.  
  317.     
  318.     def __delitem__(self, index):
  319.         if isinstance(index, slice):
  320.             (start, stop, step) = index.indices(len(self.data))
  321.             if step == -1:
  322.                 start = stop + 1
  323.                 stop = start + 1
  324.             elif step != 1:
  325.                 raise TypeError, 'invalid step in slicing deletion'
  326.             
  327.             start = min(start, stop)
  328.             self.data = self.data[:start] + self.data[stop:]
  329.         elif index < 0:
  330.             index += len(self.data)
  331.         
  332.         if index < 0 or index >= len(self.data):
  333.             raise IndexError
  334.         index >= len(self.data)
  335.         self.data = self.data[:index] + self.data[index + 1:]
  336.  
  337.     
  338.     def __setslice__(self, start, end, sub):
  339.         start = max(start, 0)
  340.         end = max(end, 0)
  341.         if isinstance(sub, UserString):
  342.             self.data = self.data[:start] + sub.data + self.data[end:]
  343.         elif isinstance(sub, basestring):
  344.             self.data = self.data[:start] + sub + self.data[end:]
  345.         else:
  346.             self.data = self.data[:start] + str(sub) + self.data[end:]
  347.  
  348.     
  349.     def __delslice__(self, start, end):
  350.         start = max(start, 0)
  351.         end = max(end, 0)
  352.         self.data = self.data[:start] + self.data[end:]
  353.  
  354.     
  355.     def immutable(self):
  356.         return UserString(self.data)
  357.  
  358.     
  359.     def __iadd__(self, other):
  360.         if isinstance(other, UserString):
  361.             self.data += other.data
  362.         elif isinstance(other, basestring):
  363.             self.data += other
  364.         else:
  365.             self.data += str(other)
  366.         return self
  367.  
  368.     
  369.     def __imul__(self, n):
  370.         self.data *= n
  371.         return self
  372.  
  373.     
  374.     def insert(self, index, value):
  375.         self[index:index] = value
  376.  
  377.  
  378. if __name__ == '__main__':
  379.     import os
  380.     (called_in_dir, called_as) = os.path.split(sys.argv[0])
  381.     (called_as, py) = os.path.splitext(called_as)
  382.     if '-q' in sys.argv:
  383.         from test import test_support
  384.         test_support.verbose = 0
  385.     
  386.     __import__('test.test_' + called_as.lower())
  387.  
  388.